#include <uart.h>

bit busy;
int zkb_buff[3];

void UartInit()
{
	SCON = 0x50;
	TMOD = 0x00;
	TL1 = BRT;
	TH1 = BRT >> 8;
	TR1 = 1;
	AUXR = 0x40;
	busy = 0;
}

void UartSendInt(int dat)
{
	while (busy);
	busy = 1;
	SBUF = ((dat/10) & 0x0f) + 48;
	while (busy);
	busy = 1;
	SBUF = ((dat%10) & 0x0f) + 48;
}

void UartSend(char dat)
{
	while (busy);
	busy = 1;
	SBUF = dat;
}

void UartSendStr(char *p)
{
	while (*p)
	{
		UartSend(*p++);
	}
}

void UartIsr() interrupt 4
{
	static zkb_i = 0;
	if (TI)
	{
		TI = 0;
		busy = 0;
	}
if (RI)
	{
		RI = 0;
		zkb_buff[zkb_i++] = SBUF;
		if(zkb_i == 3)
		{
			zkb_i = 0;
		}
	}
}